import os

root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# 更新Dockerfile以正确引用jar文件
dockerfile_content = """# 使用Java 21作为基础镜像
FROM openjdk:21-jre-slim

# 设置工作目录
WORKDIR /app

# 创建日志目录
RUN mkdir -p /app/logs

# 复制所有jar包
COPY gate-server/target/gate-server-1.0.0.jar .
COPY scene-server/target/scene-server-1.0.0.jar .
COPY login-server/target/login-server-1.0.0.jar .
COPY central-server/target/central-server-1.0.0.jar .
COPY balance-server/target/balance-server-1.0.0.jar .
COPY scripts/shell/start-all.sh .
COPY scripts/shell/stop-all.sh .

# 暴露端口
EXPOSE 8081 8082 8083 8084 8085

# 设置权限
RUN chmod +x start-all.sh
RUN chmod +x stop-all.sh

# 启动脚本
CMD ["./start-all.sh"]
"""

# 更新docker-compose.yml以正确引用jar文件
docker_compose_content = """version: '3'

services:
  gate-server:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8081:8081"
    volumes:
      - ./logs:/app/logs
    command: ["java", "-jar", "gate-server-1.0.0.jar", "--spring.profiles.active=dev"]
  
  scene-server:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8082:8082"
    volumes:
      - ./logs:/app/logs
    command: ["java", "-jar", "scene-server-1.0.0.jar", "--spring.profiles.active=dev"]
  
  login-server:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8083:8083"
    volumes:
      - ./logs:/app/logs
    command: ["java", "-jar", "login-server-1.0.0.jar", "--spring.profiles.active=dev"]
  
  central-server:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8084:8084"
    volumes:
      - ./logs:/app/logs
    command: ["java", "-jar", "central-server-1.0.0.jar", "--spring.profiles.active=dev"]
  
  balance-server:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8085:8085"
    volumes:
      - ./logs:/app/logs
    command: ["java", "-jar", "balance-server-1.0.0.jar", "--spring.profiles.active=dev"]
"""

# 写入Dockerfile
dockerfile_path = os.path.join(root, "scripts", "docker", "Dockerfile")
with open(dockerfile_path, "w", encoding="utf-8") as f:
    f.write(dockerfile_content)
print(f"更新: {dockerfile_path}")

# 写入docker-compose.yml
docker_compose_path = os.path.join(root, "scripts", "docker", "docker-compose.yml")
with open(docker_compose_path, "w", encoding="utf-8") as f:
    f.write(docker_compose_content)
print(f"更新: {docker_compose_path}")

print("✅ Docker配置已更新")